<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<script language="javascript">
	function tong()
	{
		a = eval(document.form.a_tong.value);
		b = eval(document.form.b_tong.value);
		
		if(a != "" && b != "")
		{
			document.form.c_tong.value = a + b;
		}
		else
		{
			alert("Bạn phải nhập đủ 2 số");
		}	
	}
    
   	function mod()
	{
		a = eval(document.form.a_mod.value);
		b = eval(document.form.b_mod.value);
		
		if(a != "" && b != "")
		{
			document.form.c_mod.value = a % b;
		}
		else
		{
			alert("Bạn phải nhập đủ 2 số");
		}	
	}
    
   	function hieu()
	{
		a = eval(document.form.a_hieu.value);
		b = eval(document.form.b_hieu.value);
		
		if(a != "" && b != "")
		{
			document.form.c_hieu.value = a - b;
		}
		else
		{
			alert("Bạn phải nhập đủ 2 số");
		}	
	}
    
   	function nhan()
	{
		a = eval(document.form.a_nhan.value);
		b = eval(document.form.b_nhan.value);
		
		if(a != "" && b != "")
		{
			document.form.c_nhan.value = a * b;
		}
		else
		{
			alert("Bạn phải nhập đủ 2 số");
		}	
	}
    
   	function chia()
	{
		a = eval(document.form.a_chia.value);
		b = eval(document.form.b_chia.value);
		
		if(a != "" && b != "")
		{
			document.form.c_chia.value = a / b;
		}
		else
		{
			alert("Bạn phải nhập đủ 2 số");
		}	
	}
</script>

    
 <!--Tinh a^x mod n-->   
 <script language="javascript">
	function nhiphan()
	{
		var arr = new Array();
		n = document.form.a_axn.value;
		//alert(coso);
		alert(n);
		var i = 0;		
		
		while(n > 0)
		{ 
			du = n % 2;
			alert(du);
			arr[i] = du;
			n = Math.floor(n / 2);
			i++;
			
		}
		
		var xxx;
		xxx = arr.toString();
		alert(xxx);	
	}
	
	function tinh_axn()
	{
		var arr = new Array();
		a = document.form.a_axn.value;
		xx = document.form.x_axn.value;
		x = document.form.x_axn.value;
		n = document.form.n_axn.value;
		
		var i = 0;		
		
		while(x > 0)
		{ 
			du = x % 2;
			//alert(du);
			arr[i] = du;
			x = Math.floor(x / 2);
			i++;
			
		}
		
		var xxx;
		xxx = arr.toString();
		//alert(xxx);
		/*
		Var Int Power:=1
  For i=1 to k do {
      Power:=(Power^2) mod m
      If b[i]=1 then
      Power:=(Power*x) mod m
		*/
		
		var Power = 1;
		for(k = i; k >= 0; k--) 
		{
			
			Power = (Power*Power) % n;
			if(arr[k] == 1)
				Power = (Power*a) % n;
		}
		
		//alert(Power);
		document.form.kq_axn.value = Power
	}
</script>


<script language="javascript">	
	function tinh_nghichdao()
	{
		var arr = new Array();
		a = document.form.a_tnd.value;
		m = document.form.m_tnd.value;
		mm = m;
		
		y0 = 0;
		y1 = 1;
		var i = 0;		
		
		while (a > 0)
		{
			r = m % a;
			if(r == 0) break;
			q = Math.floor(m / a);
			y = y0 - y1*q;
			m = a;
			a = r;
			y0 = y1;
			y1 = y;
		}
		if(a > 1)
			document.form.kq_tnd.value = "a không khả nghịch theo mođun m";
		else
		{
			//alert(y);
			if(-y > a)
				u = parseInt(mm) -  parseInt(-y);
			else 
				u = parseInt(y);
			document.form.kq_tnd.value = u;
		}
		
	}
</script>

	<script type="text/javascript">
		(function() {
			$(".help-tab").click(function() {
				$(".field-error").removeClass("field-error");
				$("#feedback_form")[0].reset();
				$("#feedback_form input[type='submit']").removeAttr("disabled");
				$("#feedback_form_wrapper").css("display", "none");
				$("#feedback_error").css("display", "none");
				$("#feedback_success_wrapper").css("display", "none");
				$("#help_wrapper").css("display", "block");
			});
		})(this)
	</script>



 
 
 
<style>
.input_number{
    width:22%;
    float:left;
    position:relative;
    margin: 3px;
}

.input_bt {
    width: 16%;
    float:left;
    margin:auto;
    position:relative;
    padding-left: 7px;
    padding-top:10px;
    padding-bottom: 7px;

}

.input_mod {
    width: 20%;
    float:left;
    position:relative;
    padding-top: 10px;
    padding-bottom: 5px;
    text-align: center;
    font-size: 11px;
}

.input_equal_sign {
    width: 20px;
    float:left;
    position:relative;
    padding-top:13px;
    text-align:center;
    font-weight: 600;
    font-size: 20px;
}

.introduce_operator {
    width: 300px;
    float:left;
    position:relative;
    padding-top:13px;
    margin:5px;
    text-align:center;
    font-weight: 400;
    font-size: 15px;
    color:rgb(0,0,0);
}

</style>


<div class="help-tab">
		<a href="#help-modal" rel="leanModal">EGO Calculator</a>
	</div>
<!--Content Help-->
	<section style="display: none; position: absolute; opacity: 1; z-index: 11000; left: 50%; margin-left: -249px; top: 120px;" id="help-modal" class="modal">
		<div style="display: block;" class="inner-wrapper" id="help_wrapper">
			<header>
			  <h2><span class="edx">Super EGO Calculator</span> Help You</h2>
			  <hr>
			</header>
	<form name="form" width:400px; margin:auto">
    
        <!-- Cong -->
        <div class="input_number">
		  <input type="text" name="a_tong" />
        </div>      
        
        <div class="input_bt">
		  <input type="button" name="bttong" value="+" onclick="tong();" />
        </div>
        
        <div class="input_number">
		  <input type="text" name="b_tong" />
        </div>
 
        <div class="input_equal_sign">
            =
        </div>
          
        <div class="input_number">  
		  <input type="text" name="c_tong" />
        </div>
        
        
        <!-- Tru -->
        <div class="input_number">
		  <input type="text" name="a_hieu" />
        </div>      
        
        <div class="input_bt">
		  <input type="button" name="bthieu" value="-" onclick="hieu();" />
        </div>
        
        <div class="input_number">
		  <input type="text" name="b_hieu" />
        </div>
 
        <div class="input_equal_sign">
            =
        </div>
          
        <div class="input_number">  
		  <input type="text" name="c_hieu" />
        </div>
        
        
        <!-- Nhan -->
        <div class="input_number">
		  <input type="text" name="a_nhan" />
        </div>      
        
        <div class="input_bt">
		  <input type="button" name="btnhan" value="*" onclick="nhan();" />
        </div>
        
        <div class="input_number">
		  <input type="text" name="b_nhan" />
        </div>
 
        <div class="input_equal_sign">
            =
        </div>
          
        <div class="input_number">  
		  <input type="text" name="c_nhan" />
        </div>
        
        <!-- Chia -->
        <div class="input_number">
		  <input type="text" name="a_chia" />
        </div>      
        
        <div class="input_bt">
		  <input type="button" name="btchia" value="/" onclick="chia();" />
        </div>
        
        <div class="input_number">
		  <input type="text" name="b_chia" />
        </div>
 
        <div class="input_equal_sign">
            =
        </div>
          
        <div class="input_number">  
		  <input type="text" name="c_chia" />
        </div>
        
        
        <!-- Mod -->
        <div class="input_number">
		  <input type="text" name="a_mod" />
        </div>      
        
        <div class="input_mod">
		  <input type="button" name="btmod" value="mod" onclick="mod();" />
        </div>
        
        <div class="input_number">
		  <input type="text" name="b_mod" />
        </div>
 
        <div class="input_equal_sign">
            =
        </div>
          
        <div class="input_number">  
		  <input type="text" name="c_mod" />
        </div>
        
        
        
        
        
    <div class="introduce_operator">    
   	    Tính a^x mod n, nhập lần lượt a, x, n
    </div>

        <div class="input_number">
		  <input type="text" value="37" name="a_axn" /> <br />
        </div>
        <div class="input_number">
		  <input type="text" value="27" name="x_axn" /> <br />
        </div>
        <div class="input_number">
		  <input type="text" value="101" name="n_axn" /> <br />
        </div>
        <div class="input_mod">
		  <input type="button" name="btTinhaxn" value="tính" onclick="tinh_axn();" />
        </div>
        <div class="input_number">
		  <input type="text" name="kq_axn" /> <br />
		</div>
	
    
    <div class="introduce_operator"> 
    	Tính nghịch đảo a^-1 mod m, nhập lần lượt a, m
    </div>    
        <div class="input_number">
		  <input type="text" value="30" name="a_tnd" /> <br />
        </div>
        <div class="input_number">
		  <input type="text" value="101" name="m_tnd" /> <br />
        </div>
        <div class="input_mod">
		  <input type="button" name="btTinhnd" value="tính" onclick="tinh_nghichdao();" />
        </div>
        <div class="input_number">
		  <input type="text" name="kq_tnd" /> <br />
        </div>

    

		
	</form>
		</div>
	</section>

<!--End Content Help-->









